/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.frm.bpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import merlion.scm.lcm.entity.DeliveryOrder;

/**
 *
 * @author Yuwei
 */
@Entity
public class Receipt implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String receiptId;
    private Timestamp receiptDate;
    private String receiptDateStr;
    private String financeAccountant;
    @OneToOne(targetEntity = CustomerPaymentRecord.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private CustomerPaymentRecord customerPaymentRecord;
    @OneToOne(targetEntity = DeliveryOrder.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private DeliveryOrder deliveryOrder;
    
    private static final SimpleDateFormat formatter = new SimpleDateFormat("MMMMM dd, yyyy");
    
    public Receipt(){
        receiptId = "";
        receiptDate = new Timestamp(new Date().getTime());
        receiptDateStr = convertToDateFormat(receiptDate);
        customerPaymentRecord = new CustomerPaymentRecord();
        deliveryOrder = new DeliveryOrder();
    }
    private String convertToDateFormat(Timestamp timeStamp){
        return formatter.format((java.util.Date) timeStamp);
    }
    public String getReceiptId() {
        return receiptId;
    }

    public void setReceiptId(String receiptId) {
        this.receiptId = receiptId;
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public CustomerPaymentRecord getCustomerPaymentRecord() {
        return customerPaymentRecord;
    }

    public void setCustomerPaymentRecord(CustomerPaymentRecord customerPaymentRecord) {
        this.customerPaymentRecord = customerPaymentRecord;
    }

    public DeliveryOrder getDeliveryOrder() {
        return deliveryOrder;
    }

    public void setDeliveryOrder(DeliveryOrder deliveryOrder) {
        this.deliveryOrder = deliveryOrder;
    }

    public Timestamp getReceiptDate() {
        return receiptDate;
    }

    public void setReceiptDate(Timestamp receiptDate) {
        this.receiptDate = receiptDate;
    }

    public String getReceiptDateStr() {
        return receiptDateStr;
    }

    public void setReceiptDateStr(String receiptDateStr) {
        this.receiptDateStr = receiptDateStr;
    }

    public String getFinanceAccountant() {
        return financeAccountant;
    }

    public void setFinanceAccountant(String financeAccountant) {
        this.financeAccountant = financeAccountant;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Receipt)) {
            return false;
        }
        Receipt other = (Receipt) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.frm.bpm.entity.Receipt[ id=" + id + " ]";
    }
    
}
